package hn.cch.spring.bean.aware;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;

import javax.annotation.PostConstruct;

@Configuration
public class AwareConfiguration implements BeanNameAware, ApplicationContextAware, InitializingBean {

    private static final Logger logger = LoggerFactory.getLogger(BeanNameAwareImpl.class);

    @Override
    public void setBeanName(@NonNull String beanName) {
        logger.info("setBeanName:{}", beanName);
    }

    @Override
    public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
        logger.info("setApplicationContext:{}", applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        logger.info("afterPropertiesSet");
    }

    @Autowired
    public void testAutowired(ApplicationContext applicationContext) {
        logger.info("testAutowired:{}", applicationContext);
    }

    @PostConstruct
    public void postConstruct() {
        logger.debug("postConstruct");
    }

    @Bean
    public BeanFactoryPostProcessor beanFactoryPostProcessor() {
        logger.info("beanFactoryPostProcessor");
        return new BeanFactoryPostProcessorImpl();
    }

    // @Bean(initMethod = "initMethod")
    // public ComponentBean componentBean() {
    //     logger.info("componentBean");
    //     return new ComponentBean();
    // }


}
